package com.yyy.gui.pannel;

import com.yyy.gui.listener.ConfigListener;
import com.yyy.service.ConfigService;
import com.yyy.util.ColorUtil;
import com.yyy.util.GUIUtil;

import javax.swing.*;
import java.awt.*;


/**
 * @Author：yyy
 * @Package：com.yyy.util
 * @Project：HuTuBiill
 * @name：ConfigPanel
 * @Date：2024/11/9 21:59
 * @Filename：ConfigPanel
 */
public class ConfigPanel extends WorkingPanel {

    public static ConfigPanel instance=new ConfigPanel();
    public JLabel lBudget=new JLabel("本月预算(￥)");
    public JTextField tfBudget=new JTextField("0");
    public JLabel lMysql=new JLabel("Mysql安装目录");
    public JTextField tfMysqlPath=new JTextField("");
    public JButton bSubmit=new JButton("更新");
    public ConfigPanel(){
        GUIUtil.setColor(ColorUtil.grayColor,lBudget,lMysql);
        GUIUtil.setColor(ColorUtil.blueColor,bSubmit);
        JPanel pInput=new JPanel();
        JPanel pSubmit=new JPanel();
        int gap=40;
        pInput.setLayout(new GridLayout(4,1,gap,gap));
        pInput.add(lBudget);
        pInput.add(tfBudget);
        pInput.add(lMysql);
        pInput.add(tfMysqlPath);

        pSubmit.add(bSubmit);
        this.setLayout(new BorderLayout());
        this.add(pInput,BorderLayout.NORTH);
        this.add(pSubmit,BorderLayout.CENTER);
        addListener();
    }


    @Override
    public void addListener() {
        ConfigListener configListener=new ConfigListener();
        bSubmit.addActionListener(configListener);

    }

    @Override
    public void updateData() {
        String budget=new ConfigService().get(ConfigService.budget);
        String mysqlPath=new ConfigService().get(ConfigService.mysqlpath);
        tfBudget.setText(budget);
        tfMysqlPath.setText(mysqlPath);
        tfBudget.grabFocus();

    }
}
